package poiTests;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import junit.framework.TestCase;

import org.junit.Test;

import POI.GeoServlet;

public class GeoServletTest extends TestCase {

	@Test
	public void testCreateResponse() {
		File df = new File("__temppoidate__.csv");
		boolean fe=true;
		if(!df.exists())
		{
			fe=false;
			FileWriter f;
			try {
				f = new FileWriter("__temppoidate__.csv");
				f.write("1,Chernivtsi,My,48.3,25.933\n");
				f.write("2,L'viv,Store,49.85,24.0167\n");
				f.write("3,Kyiv,Food,50.45,30.5233\n");
				f.write("4,Suceava,Recreation,47.651389,26.2556");
				f.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				fail("Temp test file is not accessible!");
			}
		};
		String response;
		GeoServlet s = new GeoServlet();
		response = s.createResponse("__temppoidate__.csv");
		assertTrue(response.split("<br>").length>0);
		assertEquals(0,(response.replaceAll("<br>", ",").split(",").length)%5);		
		if((!fe)&&(!df.delete())) fail("Can't delete temp test file!");
	}
}
